include_directories(${libyar_SOURCE_DIR}/src/include ${libyar_SOURCE_DIR}/src/lib ${libyar_BINARY_DIR}/src/include)

# source files that should be compiled into the library have
# to be added to this list
set(
	LIBYAR_SOURCEFILES
	digest.c
	endianess.c
	fheader.c
	file64.c
	operations.c
	unicode.c
)

# check whether liblzma can be used
find_library(LZMA_LIB lzma)
if(LZMA_LIB)
	list(APPEND LIBYAR_LIBRARIES ${LZMA_LIB})
endif(LZMA_LIB)

# check whether libbz2 can be used
find_library(BZIP2_LIB bz2)
if(BZIP2_LIB)
	list(APPEND LIBYAR_LIBRARIES ${BZIP2_LIB})
endif(BZIP2_LIB)

# check whether libz can be used
find_library(Z_LIB z)
if(Z_LIB)
	list(APPEND LIBYAR_LIBRARIES ${Z_LIB})
endif(Z_LIB)

# check whether libssl can be used
find_library(SSL_LIB ssl)
if(SSL_LIB)
	list(APPEND LIBYAR_LIBRARIES ${SSL_LIB})
endif(SSL_LIB)

# check whether libpthread can be used
# find_library(PTHREAD_LIB pthread)
# if(PTHREAD_LIB)
# 	list(APPEND LIBYAR_LIBRARIES ${PTHREAD_LIB})
# endif(PTHREAD_LIB)

# build shared library binary
add_library(yar SHARED ${LIBYAR_SOURCEFILES})

# link it to other libs
if(LIBYAR_LIBRARIES)
	target_link_libraries(yar ${LIBYAR_LIBRARIES})
endif(LIBYAR_LIBRARIES)

set_target_properties(yar PROPERTIES VERSION ${LIBYAR_LIBVERSION} SOVERSION ${LIBYAR_LIBVERSION})

install(
	TARGETS yar
	LIBRARY DESTINATION lib
)
